package top.wshape1.rpc.message;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import top.wshape1.rpc.common.constant.RpcMessageCodeEnum;

/**
 * @author Wshape1
 * @version 1.0
 * @description
 * @since 2024-02-02
 */

@EqualsAndHashCode(callSuper = true)
@Data
@ToString(callSuper = true)
public class RpcResponse extends RpcMessage {

    private int code;

    private String msg;

    private Exception exception;

    private Class<?> resultType;

    private Object result;

    public void setResult(Object result) {
        this.result = result;
        this.resultType = result.getClass();
    }

    public void setCodeAndMsg(RpcMessageCodeEnum codeEnum) {
        this.code = codeEnum.getCode();
        this.msg = codeEnum.getMsg();
    }

    @Override
    public int getMessageType() {
        return MessageType.RPC_RESPONSE.ordinal();
    }

    private static final long serialVersionUID = 1L;
}
